package com.duansky.servlet;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.duansky.DataPreProcess;

public class SkyServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public SkyServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request
	 *            the request send by the client to the server
	 * @param response
	 *            the response send by the server to the client
	 * @throws ServletException
	 *             if an error occurred
	 * @throws IOException
	 *             if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to
	 * post.
	 * 
	 * @param request
	 *            the request send by the client to the server
	 * @param response
	 *            the response send by the server to the client
	 * @throws ServletException
	 *             if an error occurred
	 * @throws IOException
	 *             if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		/*// 文件写到baseFilePath下的original_data.txt中
		String baseFilePath = getServletContext().getRealPath("/") + "duansky"
				+ File.separator + "data";
		InputStream in = request.getInputStream();
		File f = new File(baseFilePath, "original_data.txt");
		FileOutputStream fos = new FileOutputStream(f);
		byte[] b = new byte[1024];
		int n = 0;
		while ((n = in.read(b)) != -1) {
			System.out.println(n);
			fos.write(b, 0, n);
		}
		fos.close();
		in.close();
		
		//生成各种分析文件
		DataPreProcess.analysisData(baseFilePath, 200, 50);*/
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException
	 *             if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}
}
